<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.3"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>FabGL: ST7789_TFT/240x240/DoubleBuffer/DoubleBuffer.ino</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">FabGL
   </div>
   <div id="projectbrief">ESP32 Display Controller and Graphics Library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.3 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('_s_t7789__t_f_t_2240x240_2_double_buffer_2_double_buffer_8ino-example.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle"><div class="title">ST7789_TFT/240x240/DoubleBuffer/DoubleBuffer.ino</div></div>
</div><!--header-->
<div class="contents">
<p >Show double buffering usage</p>
<div class="fragment"><div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment">  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - &lt;http://www.fabgl.com&gt;</span></div>
<div class="line"><span class="comment">  Copyright (c) 2019-2022 Fabrizio Di Vittorio.</span></div>
<div class="line"><span class="comment">  All rights reserved.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">* Please contact fdivitto2013@gmail.com if you need a commercial license.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">* This library and related software is available under GPL v3.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">  FabGL is free software: you can redistribute it and/or modify</span></div>
<div class="line"><span class="comment">  it under the terms of the GNU General Public License as published by</span></div>
<div class="line"><span class="comment">  the Free Software Foundation, either version 3 of the License, or</span></div>
<div class="line"><span class="comment">  (at your option) any later version.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">  FabGL is distributed in the hope that it will be useful,</span></div>
<div class="line"><span class="comment">  but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><span class="comment">  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div>
<div class="line"><span class="comment">  GNU General Public License for more details.</span></div>
<div class="line"><span class="comment"></span> </div>
<div class="line"><span class="comment">  You should have received a copy of the GNU General Public License</span></div>
<div class="line"><span class="comment">  along with FabGL.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment"> * TFT Display signals:</span></div>
<div class="line"><span class="comment"> *   SCK  =&gt; GPIO 18</span></div>
<div class="line"><span class="comment"> *   MOSI =&gt; GPIO 23</span></div>
<div class="line"><span class="comment"> *   D/C  =&gt; GPIO 22</span></div>
<div class="line"><span class="comment"> *   RESX =&gt; GPIO 21</span></div>
<div class="line"><span class="comment"> */</span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &quot;<a class="code" href="fabgl_8h.html">fabgl.h</a>&quot;</span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#define TFT_SCK    18</span></div>
<div class="line"><span class="preprocessor">#define TFT_MOSI   23</span></div>
<div class="line"><span class="preprocessor">#define TFT_DC     22</span></div>
<div class="line"><span class="preprocessor">#define TFT_RESET  21</span></div>
<div class="line"><span class="preprocessor">#define TFT_SPIBUS VSPI_HOST</span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><a id="_a0" name="_a0"></a><a class="code hl_class" href="classfabgl_1_1_s_t7789_controller.html">fabgl::ST7789Controller</a> DisplayController;</div>
<div class="line"><a id="_a1" name="_a1"></a><a class="code hl_class" href="classfabgl_1_1_canvas.html">fabgl::Canvas</a>           canvas(&amp;DisplayController);</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#define DOUBLEBUFFERING 1</span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="keyword">struct </span>Test {</div>
<div class="line">  <span class="keyword">virtual</span> ~Test() { };</div>
<div class="line">  <span class="keyword">virtual</span> <span class="keywordtype">void</span> update() = 0;</div>
<div class="line">  <span class="keyword">virtual</span> <span class="keywordtype">bool</span> nextState() = 0;</div>
<div class="line">  <span class="keyword">virtual</span> <span class="keywordtype">int</span> testState() = 0;</div>
<div class="line">  <span class="keyword">virtual</span> <span class="keywordtype">char</span> <span class="keyword">const</span> * name() = 0;</div>
<div class="line">};</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &quot;ballstest.h&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;polygonstest.h&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;spritestest.h&quot;</span></div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> setup()</div>
<div class="line">{</div>
<div class="line">  DisplayController.<a id="a2" name="a2"></a><a class="code hl_function" href="classfabgl_1_1_t_f_t_controller_a968486470b4a1e512d6a24e9cee4ff85.html#a968486470b4a1e512d6a24e9cee4ff85">begin</a>(TFT_SCK, TFT_MOSI, TFT_DC, TFT_RESET, -1, TFT_SPIBUS);</div>
<div class="line">  DisplayController.<a id="a3" name="a3"></a><a class="code hl_function" href="classfabgl_1_1_t_f_t_controller_a2ac60f74ade23bfba42ef0985635589d.html#a2ac60f74ade23bfba42ef0985635589d">setResolution</a>(<a id="a4" name="a4"></a><a class="code hl_define" href="fabglconf_8h_a89682a57a015e43069041705b4cc6d89.html#a89682a57a015e43069041705b4cc6d89">TFT_240x240</a>, -1, -1, DOUBLEBUFFERING);</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// get a font for about 40x14 text screen</span></div>
<div class="line">  canvas.selectFont(&amp;fabgl::FONT_9x18);</div>
<div class="line"> </div>
<div class="line">  canvas.setGlyphOptions(GlyphOptions().<a id="a5" name="a5"></a><a class="code hl_function" href="displaycontroller_8h_a9c97194bef34db0af06bc03f6beb7903.html#a9c97194bef34db0af06bc03f6beb7903">FillBackground</a>(<span class="keyword">true</span>));</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> loop()</div>
<div class="line">{</div>
<div class="line">  <span class="keyword">static</span> int64_t stime  = esp_timer_get_time();</div>
<div class="line">  <span class="keyword">static</span> <span class="keywordtype">int</span> FPS        = 0;</div>
<div class="line">  <span class="keyword">static</span> <span class="keywordtype">int</span> FPSCounter = 0;</div>
<div class="line">  <span class="keyword">static</span> <span class="keywordtype">int</span> testIndex  = 0;</div>
<div class="line">  <span class="keyword">static</span> Test * test    = <span class="keyword">new</span> BallsTest;</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">if</span> (test-&gt;nextState() == <span class="keyword">false</span>) {</div>
<div class="line">    <span class="keyword">delete</span> test;</div>
<div class="line">    ++testIndex;</div>
<div class="line">    <span class="keywordflow">switch</span> (testIndex) {</div>
<div class="line">      <span class="keywordflow">case</span> 1:</div>
<div class="line">        test = <span class="keyword">new</span> PolygonsTest;</div>
<div class="line">        <span class="keywordflow">break</span>;</div>
<div class="line">      <span class="keywordflow">case</span> 2:</div>
<div class="line">        test = <span class="keyword">new</span> SpritesTest;</div>
<div class="line">        <span class="keywordflow">break</span>;</div>
<div class="line">      <span class="keywordflow">default</span>:</div>
<div class="line">        testIndex = 0;</div>
<div class="line">        test = <span class="keyword">new</span> BallsTest;</div>
<div class="line">        <span class="keywordflow">break</span>;</div>
<div class="line">    }</div>
<div class="line">  }</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">if</span> (esp_timer_get_time() - stime &gt; 1000000) {</div>
<div class="line">    <span class="comment">// calculate FPS</span></div>
<div class="line">    FPS = FPSCounter;</div>
<div class="line">    stime = esp_timer_get_time();</div>
<div class="line">    FPSCounter = 0;</div>
<div class="line">  }</div>
<div class="line">  ++FPSCounter;</div>
<div class="line"> </div>
<div class="line">  test-&gt;update();</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// display test state and FPS</span></div>
<div class="line">  canvas.setPenColor(<a id="a6" name="a6"></a><a class="code hl_enumvalue" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1caf5e09dd1da4088464f264b7a3118bff8">Color::Blue</a>);</div>
<div class="line">  canvas.setBrushColor(<a id="a7" name="a7"></a><a class="code hl_enumvalue" href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1ca19153c6eb83006792aac10c7eddb1df6">Color::BrightYellow</a>);</div>
<div class="line">  canvas.drawTextFmt(0, 0, <span class="stringliteral">&quot; %d %s at %d FPS &quot;</span>, test-&gt;testState(), test-&gt;name(), FPS);</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">if</span> (DOUBLEBUFFERING)</div>
<div class="line">    canvas.swapBuffers();</div>
<div class="line"> </div>
<div class="line">}</div>
<div class="ttc" id="aclassfabgl_1_1_canvas_html"><div class="ttname"><a href="classfabgl_1_1_canvas.html">fabgl::Canvas</a></div><div class="ttdoc">A class with a set of drawing methods.</div><div class="ttdef"><b>Definition:</b> <a href="canvas_8h_source.html#l00070">canvas.h:70</a></div></div>
<div class="ttc" id="aclassfabgl_1_1_s_t7789_controller_html"><div class="ttname"><a href="classfabgl_1_1_s_t7789_controller.html">fabgl::ST7789Controller</a></div><div class="ttdoc">Implements ST7789 display driver controller.</div><div class="ttdef"><b>Definition:</b> <a href="_t_f_t_controller_specif_8h_source.html#l00069">TFTControllerSpecif.h:69</a></div></div>
<div class="ttc" id="aclassfabgl_1_1_t_f_t_controller_a2ac60f74ade23bfba42ef0985635589d_html_a2ac60f74ade23bfba42ef0985635589d"><div class="ttname"><a href="classfabgl_1_1_t_f_t_controller_a2ac60f74ade23bfba42ef0985635589d.html#a2ac60f74ade23bfba42ef0985635589d">fabgl::TFTController::setResolution</a></div><div class="ttdeci">void setResolution(char const *modeline, int viewPortWidth=-1, int viewPortHeight=-1, bool doubleBuffered=false)</div><div class="ttdoc">Sets TFT resolution and viewport size.</div><div class="ttdef"><b>Definition:</b> <a href="_t_f_t_controller_generic_8cpp_source.html#l00224">TFTControllerGeneric.cpp:224</a></div></div>
<div class="ttc" id="aclassfabgl_1_1_t_f_t_controller_a968486470b4a1e512d6a24e9cee4ff85_html_a968486470b4a1e512d6a24e9cee4ff85"><div class="ttname"><a href="classfabgl_1_1_t_f_t_controller_a968486470b4a1e512d6a24e9cee4ff85.html#a968486470b4a1e512d6a24e9cee4ff85">fabgl::TFTController::begin</a></div><div class="ttdeci">void begin(SPIClass *spi, gpio_num_t DC, gpio_num_t RESX=GPIO_UNUSED, gpio_num_t CS=GPIO_UNUSED, gpio_num_t BL=GPIO_UNUSED, int freq=40000000)</div><div class="ttdoc">Initializes TFT display controller with Arduino style SPIClass object.</div><div class="ttdef"><b>Definition:</b> <a href="_t_f_t_controller_generic_8cpp_source.html#l00158">TFTControllerGeneric.cpp:158</a></div></div>
<div class="ttc" id="adisplaycontroller_8h_a9c97194bef34db0af06bc03f6beb7903_html_a9c97194bef34db0af06bc03f6beb7903"><div class="ttname"><a href="displaycontroller_8h_a9c97194bef34db0af06bc03f6beb7903.html#a9c97194bef34db0af06bc03f6beb7903">FillBackground</a></div><div class="ttdeci">GlyphOptions &amp; FillBackground(bool value)</div><div class="ttdoc">Helper method to set or reset fillBackground.</div><div class="ttdef"><b>Definition:</b> <a href="displaycontroller_8h_source.html#l00015">displaycontroller.h:15</a></div></div>
<div class="ttc" id="afabgl_8h_html"><div class="ttname"><a href="fabgl_8h.html">fabgl.h</a></div><div class="ttdoc">This file is the all in one include file. Application can just include this file to use FabGL library...</div></div>
<div class="ttc" id="afabglconf_8h_a89682a57a015e43069041705b4cc6d89_html_a89682a57a015e43069041705b4cc6d89"><div class="ttname"><a href="fabglconf_8h_a89682a57a015e43069041705b4cc6d89.html#a89682a57a015e43069041705b4cc6d89">TFT_240x240</a></div><div class="ttdeci">#define TFT_240x240</div><div class="ttdef"><b>Definition:</b> <a href="fabglconf_8h_source.html#l00338">fabglconf.h:338</a></div></div>
<div class="ttc" id="agroup___enumerations_gab87bacfdad76e61b9412d7124be44c1c_html_ggab87bacfdad76e61b9412d7124be44c1ca19153c6eb83006792aac10c7eddb1df6"><div class="ttname"><a href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1ca19153c6eb83006792aac10c7eddb1df6">fabgl::BrightYellow</a></div><div class="ttdeci">@ BrightYellow</div><div class="ttdef"><b>Definition:</b> <a href="displaycontroller_8h_source.html#l00214">displaycontroller.h:214</a></div></div>
<div class="ttc" id="agroup___enumerations_gab87bacfdad76e61b9412d7124be44c1c_html_ggab87bacfdad76e61b9412d7124be44c1caf5e09dd1da4088464f264b7a3118bff8"><div class="ttname"><a href="group___enumerations_gab87bacfdad76e61b9412d7124be44c1c.html#ggab87bacfdad76e61b9412d7124be44c1caf5e09dd1da4088464f264b7a3118bff8">fabgl::Blue</a></div><div class="ttdeci">@ Blue</div><div class="ttdef"><b>Definition:</b> <a href="displaycontroller_8h_source.html#l00207">displaycontroller.h:207</a></div></div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Mon Aug 29 2022 13:52:04 for FabGL by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.3 </li>
  </ul>
</div>
</body>
</html>
